<?php
include_once 'app/until/GetData.php';
include_once 'app/until/GFW_HTTP.php';

class MailBox extends GetData{

	private $daten;
	public $User_Id;
	public $mails;

	public function __construct($match){
		$this->daten = $match;

		if (!isset($_SESSION['UserId'])){
			HTTP::redirect ( BASE_URL . '/NotLogin' );
		}else{
			$this->User_Id = $_SESSION ['UserId'];
		}
	}

	public function getWort(RainTPL $design){
		$get_mails = $this->design->post->gfw_mail;
		$DBMail = new Db_Mail();
		if ($this->User_Id){
			if (!empty($get_mails)){
				$countdelmails = 0;

				foreach ($this->design->post->gfw_mail as $id){
					if($DBMail->delMail($this->User_Id,$id))
					{
						$countdelmails++;
					}
				}
				HTTP::redirect ( BASE_URL . '/mailbox?succes='.$countdelmails);
			}elseif(isset($this->daten['Del_ID'])){
			    if($DBMail->delMail($this->User_Id,$this->daten['Del_ID'])){
					HTTP::redirect ( BASE_URL . '/mailbox');
				}else{
				    HTTP::redirect ( BASE_URL . '/mailbox/error');
				}
			}else{
				$this->mails = $DBMail->GetAllMails($this->User_Id);
				
				$crumb = new Crumb($design,2);
        		$this->design->debugging = true;
        		$this->design->caching = false;
        		$this->design->assign ('bcn', $crumb->getCrumb_Name());
        		$this->design->assign ('bcrumb',$crumb->getCrumb());
				$this->design->assign ('Mails',$this->mails);
				$this->design->display($this->design->ln.'/mail/mailbox.tpl');
			}

		}
	}

}
?>